<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加</title>
<link rel="stylesheet" href="${pageContext.request.contextPath }/static/css/bootstrap.css"/>
<link rel="stylesheet" href="${pageContext.request.contextPath }/static/css/2.css"/>
</head>
<body> 
<div class="page-header">
    <h1>添加</h1>
    <h1 id="addInfo" style="color: red"></h1>
</div>
<form action="" method="" id="form" >
    <table class="table table-hover">
        <tr class="active">
            <td>
                <label for="uploader">图书名称:</label></td>
            <td>
                <input type="text"   class="form-control" name="title" id="title" placeholder="请输入图书标题">
            </td>
        </tr>
        <tr class="warning">
            <td><label for="summary">图书摘要:</label></td>
            <td>
                <div class="form-group">
                    <textarea id="summary" style="resize: none" name="summary" class="form-control" rows="3" placeholder="请输入摘要"></textarea>
                </div>
            </td>
        </tr>
        <tr class="active">
            <td>
                <label for="uploader">图书类别:</label></td>
            <td>
                <select name="categoryid" class="form-control" >
                    <option value="0">全部</option>
                    <c:forEach items="${categoryList}" var="category">
                        <option  value="${category.id}">${category.name}</option>
                    </c:forEach>
                </select>
            </td>
        </tr>
        <tr class="active">
            <td>
                <label for="uploader">上传人:</label></td>
            <td>
                <input type="text"   class="form-control" name="uploader" id="uploader" placeholder="请输入上传人">
            </td>
        </tr>
        <tr class="active">
            <td>
                <label for="uploader">上传时间:</label></td>
            <td>
                <input type="date"class="form-control" name="createdate" id="createdate" placeholder="请输入上传时间">
            </td>
        </tr>
        <tr class="danger">
            <td colspan="2">
                <input type="button" onclick="add()" class="btn btn-danger" value="添加"/>
            </td>
        </tr>
    </table>
	</form>
</body>
<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/jquery.date.js"></script>
<script>
    $.date('#productionDate');
    function preview(file){
        var prevDiv = document.getElementById('preview');
        if (file.files && file.files[0]){
            reader = new FileReader();
            reader.onload = function(evt){
                prevDiv.innerHTML = '<img src="' + evt.target.result + '" />';
            }
            reader.readAsDataURL(file.files[0]);
        }else{
            prevDiv.innerHTML = '<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
        }
    }

    function add(){
        var data=$("#form").serialize();
        $.ajax({
            url:"${pageContext.request.contextPath}/entry/add",
            data:data,
            type:"get",
            success:function (result) {
                if (result.code==0){
                    location.href="${pageContext.request.contextPath}/entry/list"
                } else {
                    $("#addInfo").html(result.msg);
                }
            },
            dataType:"json",
            error:function () {
                alert("1111")
            }

        })
    }
</script>
</html>